package com.twu.biblioteca.command;


import com.twu.biblioteca.LibraryController;
import com.twu.biblioteca.model.Book;

public class ListBooksCommand implements Command {

    private LibraryController libraryController;

    public ListBooksCommand(LibraryController libraryController) {
        this.libraryController = libraryController;
    }

    @Override
    public void execute() {
        StringBuilder sb = new StringBuilder();
        sb.append("All books with details. \n");
        for (Book book : libraryController.getBooks()){
            if (book.isAvailable()){
                sb.append("  ID: ").append(book.getId()).append(" Name: ").append(book.getName());
                sb.append("  Author: ").append(book.getAuthor()).append(" Year Published: ").append(book.getYear()).append("\n");
            }
        }
        System.out.println(sb.toString());
    }
}
